﻿
//
//
//

namespace Microsoft.OpenTurf.Silverlight.Shared
{
    using System.ServiceModel.Syndication;

    public class KmlTranslator : ITranslator<IFeedItem, SyndicationItem>
    {
        public IFeedItem Translate(IFeedItem genericFeedItem, SyndicationItem concreteFeedItem)
        {
            genericFeedItem.ID = concreteFeedItem.Id;
            genericFeedItem.Title = concreteFeedItem.Title.Text;
            genericFeedItem.Description = concreteFeedItem.Summary.Text;

            foreach (SyndicationLink link in concreteFeedItem.Links)
            {
                if (link.RelationshipType.Equals("enclosure"))
                {
                    if (link.MediaType.Equals("application/vnd.google-earth.kml+xml"))
                    {
                        genericFeedItem.Link = link.Uri;
                    }
                    else if (link.MediaType.Contains("image"))
                    {
                        genericFeedItem.Icon = link.Uri;
                    }
                }
            }

            return genericFeedItem;
        }
    }
}
